<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:insert="~{include :: header('文库详情')}" />
    <style>
        .form-header{
            border-bottom: 1px solid #e2e2e2;
            margin-bottom: 30px;
            padding-left: 8px;
        }
    </style>
</head>
<body class="hold-transition">
<div class="container-fluid mt-2 mb-2">
    <form class="form-horizontal" onsubmit="return false;">
        <div class="row form-header">
            <div class="col-sm-8">
                <i class="fa fa-file-powerpoint-o h4"></i> <span class="h4" th:text=" ${document.title}"></span>
            </div>
            <div class="col-sm-4 text-sm-center">
                <a class="btn btn-success btn-sm" th:onclick="documentEdit([[${document.id}]])"><i class="fa fa-edit"></i> 修改</a>
                <a th:href="${document.fileUrl}" th:download="${document.title}" class="btn btn-warning btn-sm"><i class="fa fa fa-download"></i> 下载文件</a>
                <a th:if="${document.status == 0}" class="btn btn-primary btn-sm" th:onclick="documentApproval(1)"><i class="fa fa-edit"></i> 通过</a>
                <a th:if="${document.status == 0}" class="btn btn-danger btn-sm" th:onclick="documentApproval(-1)"><i class="fa fa-edit"></i> 驳回</a>
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 text-sm-right col-form-label">机构:</label>
            <span class="col-sm-3 col-form-label" th:text="${company.companyName}"></span>
            <label class="col-sm-2 text-sm-right col-form-label">标签:</label>
            <div class="col-sm-3 col-form-label" >
                <span style="margin-right: 10px" th:each="item :  ${#strings.arraySplit(document.tags, '，')}"  th:text="${item}"></span>
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 text-sm-right col-form-label">频道:</label>
            <span class="col-sm-3 col-form-label" th:text="${channel.channelName}"></span>
            <label class="col-sm-2 text-sm-right col-form-label">专业:</label>
            <span class="col-sm-3 col-form-label" th:text="${subject.subjectName}"></span>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 text-sm-right col-form-label">分类:</label>
            <span class="col-sm-3 col-form-label" th:text="${documentType}"></span>
            <label class="col-sm-2 text-sm-right col-form-label">类别:</label>
            <span class="col-sm-3 col-form-label" th:text="${document.categoryName}"></span>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 text-sm-right col-form-label">文件大小:</label>
            <div class="col-sm-3 col-form-label">
                <span class="text-red" th:text="${document.fileSize/1024} + 'KB'"></span>
            </div>
            <label class="col-sm-2 text-sm-right col-form-label">拓展名:</label>
            <span class="col-sm-3 col-form-label" th:text="${document.fileExt}"></span>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 text-sm-right col-form-label">浏览数:</label>
            <span class="col-sm-3 col-form-label" th:text="${document.viewCount}"></span>
            <label class="col-sm-2 text-sm-right col-form-label">下载数:</label>
            <span class="col-sm-3 col-form-label" th:text="${document.downCount}"></span>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 text-sm-right col-form-label">点赞数:</label>
            <span class="col-sm-3 col-form-label" th:text="${document.likeCount}"></span>
            <label class="col-sm-2 text-sm-right col-form-label">上传人:</label>
            <span class="col-sm-3 col-form-label" th:text="${document.userName}+'('+${document.userId}+')'"></span>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 text-sm-right col-form-label">价格:</label>
            <span class="col-sm-3 text-red col-form-label" th:text="${document.price/100}+'元'"></span>
            <label class="col-sm-2 text-sm-right col-form-label">等级:</label>
            <span class="col-sm-3 col-form-label" th:text="${member}"></span>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 text-sm-right col-form-label">状态:</label>
            <span th:class="${document.status == 1?'col-sm-3 text-blue col-form-label':'col-sm-3 text-red col-form-label'}" th:text="${document.status == 0?'未审核':document.status == 1?'已通过':document.status == -1?'已驳回':'未知'}"></span>
            <label class="col-sm-2 text-sm-right col-form-label">属性:</label>
            <div class="col-sm-2 pt-2">
                <label for="isElite"><input type="checkbox" value="1" name="isElite" id="isElite" th:checked="${document.isElite==1}" onchange="isEliteClicked()"> 推荐</label>
                <label for="isTop"><input type="checkbox" value="1" name="isTop" id="isTop" th:checked="${document.isTop==1}" onchange="isTopClicked()"> 固顶</label>
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 text-sm-right col-form-label">封面图:</label>
            <span class="col-sm-8 text-red col-form-label" onclick="viewImage(this.innerText)" th:text="${document.cover}"></span>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 text-sm-right col-form-label">文件路径:</label>
            <span class="col-sm-8 text-red col-form-label" th:text="${document.fileUrl}"></span>
        </div>
        <div class="form-group row" th:if="${document.status != 0}">
            <label class="col-sm-2 text-sm-right col-form-label">审核人:</label>
            <span class="col-sm-3 text-red col-form-label" th:text="${document.censorName}+'('+${document.censorId}+')'"></span>
            <label class="col-sm-2 text-sm-right col-form-label">审核时间:</label>
            <div class="col-sm-2 pt-2">
                <span class="col-sm-3 col-form-label" th:text="${#strings.replace(document.censorTime,'T',' ')}"></span>
            </div>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 text-sm-right col-form-label">创建时间:</label>
            <span class="col-sm-3 col-form-label" th:text="${#strings.replace(document.createTime,'T',' ')}"></span>
        </div>
        <div class="form-group row">
            <label class="col-sm-2 text-sm-right col-form-label">简介:</label>
            <div class="col-sm-8 col-form-label" th:text="${document.intro}"></div>
        </div>
    </form>
</div>
<th:block th:insert="~{include :: footer}" />
<script th:inline="javascript">

    var prefix = "/document";
    var documentId = [[${document.id}]]

    function viewImage(imgSrc) {
        layer.open({
            type: 1,
            skin: 'layui-layer-rim',
            title: false,
            shadeClose: true,
            area: ['480', '365px'],
            content: '<img src="' + imgSrc + '" />'
        });
    }

    //编辑
    function documentEdit(id) {
        var index = layer.open({
            title: '编辑资料',
            content: prefix+"/edit.html?id="+id,
            type: 2,
            shade: 0.2,
            maxmin: true,
            shadeClose: true,
            area: ['85%','90%']
        });
    }

    //审核
    function documentApproval(status) {
        if(status == 0 || status > 1 || status < -1){
            $.modal.msgError("参数错误");
            return false;
        }
        var index = layer.open({
            title: '资料审核',
            content: prefix+"/approval.html?id="+documentId+"&status="+status,
            type: 2,
            shade: 0.2,
            maxmin: true,
            shadeClose: true,
            area: ['65%','95%']
        });
    }

    //推荐开关操作
    function isTopClicked() {
        var isTop = $("#isTop").prop("checked") ? 1 : 0;
        var msg = "";
        if (isTop > 0) {
            msg = "确认要把排序改为置顶吗?"
        } else {
            msg = "确认要把排序取消置顶吗?"
        }
        $.modal.confirm(msg, function () {
            var data = {"id": documentId, "isTop": isTop};
            $.post(prefix + "/top/clicked.json",data,function (json) {
                if(json.code === 0){
                    location.reload()
                }
            })
        });
    }

    //置顶开关操作
    function isEliteClicked() {
        var isElite = $("#isElite").prop("checked") ? 1 : 0;
        var msg = "";
        if(isElite > 0){
            msg = "确认要把排序改为推荐吗?"
        }else {
            msg = "确认要把排序取消推荐吗?"
        }
        $.modal.confirm(msg, function () {
            var data = {"id": documentId, "isElite": isElite};
            $.post(prefix + "/elite/clicked.json",data,function (json) {
                if(json.code === 0){
                    location.reload()
                }
            })
        });
    }

</script>
</body>
</html>